<html  xmlns:v-bind="http://www.w3.org/1999/xhtml" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0"/>
    <title>dati</title>

    <meta http-equiv="X-UA-Compatible" content="IE=Edge"/>

    <script src="/js/common.js"></script>
</head>
<body>
<style>
    .container{
        max-width: 1000px;
        background-color: transparent;
        min-height: 100%;
    }

</style>

<script src="/js/common.js"></script>
<div class="container" id="app" >
    <div class="post">
    <div class="form-group">
        <label >用户名：</label>
        <input  class="form-control" name="userName"  type="text" v-model="userName"  v-bind:value="userName" required placeholder="用户名"/>
    </div>
    <div class="form-group">
        <label >密码：</label>
        <input  class="form-control" name="userName"  type="text" v-model="password"  v-bind:value="password" required placeholder="密码"/>
    </div>
    <div class="form-group">
        <label >收货人：</label>
        <input  class="form-control" name="userName"  type="text" v-model="receiver" v-bind:value="receiver" required placeholder="收货人"/>
    </div>
    <div class="form-group">
        <label >收货地址：</label>
        <input  class="form-control" name="userName"  type="text" v-model="address" v-bind:value="address" required placeholder="收货地址"/>
    </div>
    <div class="form-group">
        <label >手机号码：</label>
        <input  class="form-control" name="userName"  type="text" v-model="phone" v-bind:value="phone" required placeholder="手机号码"/>
    </div>
    <div class="form-group"> <button  class="btn btn-primary  btn-block" v-on:click="updateUserInfo()">修改</button></div>
     </div>
</div>
<script>

    var app = new Vue({
        el: '#app',
        data: {
            type: '',
            userName: '',
            password: '',
            address: '',
            phone: '',
            receiver: '',
            items: [
            ]
        },
        methods: {
            updateUserInfo: function () {
                if (!app.phone.match('^1(3|4|5|7|8)\\d{9}$')) {
                    alert("手机号码格式不正确");
                    return false;
                }
                if (app.password==""){
                    alert("密码不能为空");
                    return false;
                }
                    var data = {
                            userName:app.userName,
                            password:app.password,
                            address:app.address,
                            phone:app.phone,
                            receiver:app.receiver,
                    };
                    $.ajax({
                        cache: true,
                        type: "POST",
                        url: "/user/updateUserInfo",
                        data: data,
                        error: function (request) {
                            alert("连接错误")
                        },
                        success: function (data) {
                            if (data.code == 200) {
                                alert("修改成功")
                                location.reload();
                            }
                            if (data.code == 404) {
                                alert("用户名或密码错误");
                            }

                        }
                    })

            },
        }
    });
    $(document).ready(function(){
        var params1={
        }
        $.ajax({
            type : "post",
            url : "/user/getUserInfo",
            data : params1,
            success : function(data) {
                app.address=data.user.address;
                app.phone=data.user.phone;
                app.receiver=data.user.receiver;
                app.password=data.user.password;
                app.userName=data.user.userName;
            }
        });
    })

</script>
</body>
</html>
